package interfaze;

import java.awt.Color;
import java.awt.Font;
import java.awt.Image;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;

import constants.PercentNumber;

import logic.Utilities;

/** Brick Breaker Pause Panel's class.
 * @author Team 1
 *
 */
@SuppressWarnings("serial")
public class BrickBreakerPausePanel extends JPanel implements ActionListener, MouseListener {
	
	private SuperArcade2in1 window;							//The JFrame in which this panel is being added.
	private JLabel background = new JLabel();				//The background of this panel.
	private JLabel lTitle = new JLabel("PAUSE");			//The pause title.
	private JButton bResume = new JButton("Resume");		//The Resume button.
	private JButton bOptions = new JButton("Options");		//The Options button.
	private JButton bExit = new JButton("Exit");			//The Exit button.
	private Font font;										//The font that is used for all the buttons.
	
	/**BrickBreakerPausePanel's constructor.
	 * @param window : The JFrame in which this panel is being added.
	 */
	public BrickBreakerPausePanel(SuperArcade2in1 window) {
		this.window = window;
		
		//Sets the panel's layout to null in order to work with absolute coordinates.
		this.setLayout(null);
		
		//Sets the font that is going to be used by all the buttons.
		font = new Font("Helvetica", Font.PLAIN, Math.round(12 * window.xScale));
		
		//Sets the background
		Image image = logic.Utilities.loadImage("res/background.png");
		if(window.xScale != 1 || window.yScale != 1) {
			image = Utilities.resizeImage(window.xScale, window.yScale, "res/background.png");
		}
		background.setIcon(new ImageIcon(image));
		background.setBounds(0, 0, image.getWidth(null), image.getHeight(null));
		
		//Sets the components of the panel. It boundaries, font and so on.
		lTitle.setFont(new Font("Helvetica", Font.BOLD, (int) Math.round(75 * window.xScale)));
		lTitle.setForeground(Color.WHITE);
		lTitle.setBounds(Math.round((window.width / 2) - (260 * window.xScale / 2)), Math.round(200 * window.yScale),
				Math.round(260 * window.xScale), Math.round(100 * window.yScale));
		
		bResume.setBounds(Math.round(((window.width / 2) - (100 * window.xScale / 2))), Math.round(350 * window.yScale),
				Math.round(100 * window.xScale), Math.round(25 * window.yScale));
		bResume.setFont(font);
		bOptions.setBounds(Math.round(((window.width / 2) - (100 * window.xScale / 2))), Math.round(380 * window.yScale),
				Math.round(100 * window.xScale), Math.round(25 * window.yScale));
		bOptions.setFont(font);
		bExit.setBounds(Math.round(((window.width / 2) - (100 * window.xScale / 2))), Math.round(410 * window.yScale),
				Math.round(100 * window.xScale), Math.round(25 * window.yScale));
		bExit.setFont(font);
		
		//Adds the components to the panel.
		this.add(lTitle);
		this.add(bResume);
		this.add(bOptions);
		this.add(bExit);
		this.add(background);
		
		//Adds their listeners.
		bResume.addActionListener(this);
		bOptions.addActionListener(this);
		bExit.addActionListener(this);
		bResume.addMouseListener(this);
		bOptions.addMouseListener(this);
		bExit.addMouseListener(this);
	}

	@Override
	public void actionPerformed(ActionEvent e) {
		if(e.getSource().equals(bResume)) {
			//Redirects to the gaming panel with the load flag set as true, so the other zeroes means nothing.
			this.setVisible(false);
			BrickBreakerGamingPanel panel = new BrickBreakerGamingPanel(window, true, 0, 0, 0, 0, 0, 0, 0, 0, PercentNumber.ZERO, 0, 0);
			window.add(panel);
			panel.requestFocus();
			window.remove(this);
		} else if(e.getSource().equals(bOptions)) {
			//Redirects to the options panel.
			window.add(new BrickBreakerOptionsPanel(window, "PauseMenu"));
			this.setVisible(false);
			window.remove(this);
		} else if(e.getSource().equals(bExit)) {
			//Redirects to the main menu panel.
			window.add(new BrickBreakerMainMenuPanel(window));
			this.setVisible(false);
			window.remove(this);
		}
	}

	@Override
	public void mouseClicked(MouseEvent e) {
		
	}

	@Override
	public void mouseEntered(MouseEvent e) {
		//Increases the buttons size when the mouse enters them.
		if(e.getSource().equals(bResume)) {
			Utilities.buttonEffect(bResume, 5, window.xScale, window.yScale);
		} else if(e.getSource().equals(bOptions)) {
			Utilities.buttonEffect(bOptions, 5, window.xScale, window.yScale);
		} else if(e.getSource().equals(bExit)) {
			Utilities.buttonEffect(bExit, 5, window.xScale, window.yScale);
		}
	}

	@Override
	public void mouseExited(MouseEvent e) {
		//Decreases the buttons size when the mouse enters them.
		if(e.getSource().equals(bResume)) {
			Utilities.buttonEffect(bResume, -5, window.xScale, window.yScale);
		} else if(e.getSource().equals(bOptions)) {
			Utilities.buttonEffect(bOptions, -5, window.xScale, window.yScale);
		} else if(e.getSource().equals(bExit)) {
			Utilities.buttonEffect(bExit, -5, window.xScale, window.yScale);
		}
	}

	@Override
	public void mousePressed(MouseEvent e) {
		
	}

	@Override
	public void mouseReleased(MouseEvent e) {
		
	}
}
